
<template>
	<div>
		<InputOutputDefine
			:versionId="props.id"
			:stepCode="props.nodeId"
			:resource="props.frontFile"
			:inputFlag="true"
			:topFlag="false"
			:outputFlag="false"
		></InputOutputDefine>
		<a-row>
			<a-col span="24">
				<a-radio-group
					v-if="props.componentConfig?.config"
					v-model:value="props.componentConfig.config.upperTrans"
					@click="upperRadioClick"
					@change="radioOnChange"
				>
					<a-radio value="upper">
						<Icon type="logo-apple"></Icon>
						<span>转大写</span>
					</a-radio>
					<a-radio value="lower">
						<Icon type="logo-android"></Icon>
						<span>转小写</span>
					</a-radio>
				</a-radio-group>

				<a-radio-group
					v-if="props.componentConfig?.config"
					v-model:value="props.componentConfig.config.underLineTrans"
					@click="underLineRadioClick"
					@change="radioOnChange"
				>
					<a-radio value="cameCase">
						<Icon type="logo-apple"></Icon>
						<span>下划线转驼峰</span>
					</a-radio>
					<a-radio value="underLine">
						<Icon type="logo-android"></Icon>
						<span>驼峰转下划线</span>
					</a-radio>
				</a-radio-group>
			</a-col>
		</a-row>
		<a-row>
			<a-col span="24">
				<ParamDefine
					v-if="props.componentConfig?.config"
					:params="props.componentConfig.config.output"
					:isViewBasicFieldFlag="false"
					:isViewArrayFlag="false"
					:isAddColumnFlag="false"
					:isActionColumnFlag="false"
					:isUpdateColumnFlag="false"
					:jsonEditorFlag="false"
					:isRemoveColumnFlag="false"
					:isAddChildrenColumnFlag="false"
					:isMappingColumnFlag="false"
					ref="left"
				>
				</ParamDefine>
			</a-col>
		</a-row>
	</div>
</template>


<script setup>
import { onMounted, ref, watch, toRaw, inject, getCurrentInstance } from 'vue'
import processVersionContentApi from '@/api/process/processVersionContentApi'
import ParamDefine from '@/views/restapi/ParamDefine.vue'
import { mergeStepConfigToFrontFile, hasProperties } from '@/utils'

const props = defineProps(['componentConfig', 'nodeId', 'id', 'frontFile'])

const left = ref()

const defaultConfig = () => {
	return {
		config: {
			output: {
				params: [],
				basicTypeFlag: false,
				isArrayFlag: false,
				isActionColumnFlag: false,
				isMappingColumnFlag: false
			},
			upperTrans: '',
			underLineTrans: ''
		}
	}
}

onMounted(async () => {
	if (!hasProperties(props.componentConfig)) {
		const c = defaultConfig()
		props.componentConfig.config = c.config
	}
	queryOutput()
})

const upperRadioClick = () => {
	if (props.componentConfig.config.upperTrans && props.componentConfig.config.upperTrans != '') {
		props.componentConfig.config.upperTrans = ''
		radioOnChange()
	}
}

const underLineRadioClick = () => {
	if (props.componentConfig.config.underLineTrans && props.componentConfig.config.underLineTrans != '') {
		props.componentConfig.config.underLineTrans = ''
		radioOnChange()
	}
}

const getResource = () => {
	let frontFile = mergeStepConfigToFrontFile(props.frontFile, props.nodeId, props.componentConfig)
	return frontFile
}

const getOutputDefine = async () => {
	let resource = getResource()
	//需要调用后端查询接口定义
	const read = await processVersionContentApi.getCurrentOutputDefine({
		id: props.id,
		frontFile: resource,
		stepCode: props.nodeId
	})
	return read
}

const queryOutput = async () => {
	const c = await getOutputDefine()
	const cb = left.value.repairJson(c)
	props.componentConfig.config.output = cb
}

const radioOnChange = async () => {
	await queryOutput()
}
//现在开始处理
</script>

<style scoped></style>
